
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>微信H5支付 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="wxapp.html" />
    
    
    <link rel="prev" href="appPay.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    项目导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../contact.html">
            
                <a href="../../contact.html">
            
                    
                    联系方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../study.html">
            
                <a href="../../study.html">
            
                    
                    学习资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../gitchat.html">
            
                <a href="../../gitchat.html">
            
                    
                    GitChat交流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../blog/">
            
                <a href="../../blog/">
            
                    
                    我的博客
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../opensource/">
            
                <a href="../../opensource/">
            
                    
                    开源项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../opensource/IJPay.html">
            
                <a href="../../opensource/IJPay.html">
            
                    
                    What is a IJPay?
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../opensource/JPay.html">
            
                <a href="../../opensource/JPay.html">
            
                    
                    Android支付SDK-JPay
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../opensource/weixin_guide.html">
            
                <a href="../../opensource/weixin_guide.html">
            
                    
                    极速开发微信公众号
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../">
            
                <a href="../">
            
                    
                    IJPay 文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../IJPay-Demo.html">
            
                <a href="../../IJPay-Demo.html">
            
                    
                    IJPay-Demo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../alipay/">
            
                <a href="../alipay/">
            
                    
                    支付宝支付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.1" data-path="../alipay/alipay-config.html">
            
                <a href="../alipay/alipay-config.html">
            
                    
                    配置应用环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.2" data-path="../alipay/alipay-init.html">
            
                <a href="../alipay/alipay-init.html">
            
                    
                    IJPay 支付宝初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.3" data-path="../alipay/alipay-wap.html">
            
                <a href="../alipay/alipay-wap.html">
            
                    
                    支付宝手机网站支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.4" data-path="../alipay/alipay-pc.html">
            
                <a href="../alipay/alipay-pc.html">
            
                    
                    支付宝电脑网站支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5" data-path="../alipay/alipay-offline.html">
            
                <a href="../alipay/alipay-offline.html">
            
                    
                    当面付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.5.1" data-path="../alipay/alipay-offline/alipay-qrPay.html">
            
                <a href="../alipay/alipay-offline/alipay-qrPay.html">
            
                    
                    支付宝扫码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5.2" data-path="../alipay/alipay-offline/alipay-barPay.html">
            
                <a href="../alipay/alipay-offline/alipay-barPay.html">
            
                    
                    支付宝条码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5.3" data-path="../alipay/alipay-offline/alipay-wavePay.html">
            
                <a href="../alipay/alipay-offline/alipay-wavePay.html">
            
                    
                    支付宝声波支付
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.2.6" data-path="../alipay/alipay-coupon.html">
            
                <a href="../alipay/alipay-coupon.html">
            
                    
                    支付宝红包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.7" data-path="../alipay/alipay-transfer.html">
            
                <a href="../alipay/alipay-transfer.html">
            
                    
                    支付宝提现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.8" data-path="../alipay/alipay-app.html">
            
                <a href="../alipay/alipay-app.html">
            
                    
                    支付宝APP支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.9" data-path="../alipay/alipay-notify.html">
            
                <a href="../alipay/alipay-notify.html">
            
                    
                    支付宝服务端异步通知
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.10" data-path="../alipay/alipay-api.html">
            
                <a href="../alipay/alipay-api.html">
            
                    
                    支付宝API字典
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="./">
            
                <a href="./">
            
                    
                    微信支付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.3.1" data-path="wxapi.html">
            
                <a href="wxapi.html">
            
                    
                    微信公用API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.2" data-path="allapi.html">
            
                <a href="allapi.html">
            
                    
                    微信支付API接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.3" data-path="micropay.html">
            
                <a href="micropay.html">
            
                    
                    微信刷卡支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.4" data-path="wechatPay.html">
            
                <a href="wechatPay.html">
            
                    
                    微信公众号支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.5" data-path="qrPay.html">
            
                <a href="qrPay.html">
            
                    
                    微信扫码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.6" data-path="appPay.html">
            
                <a href="appPay.html">
            
                    
                    微信APP支付
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.3.7" data-path="H5.html">
            
                <a href="H5.html">
            
                    
                    微信H5支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.8" data-path="wxapp.html">
            
                <a href="wxapp.html">
            
                    
                    微信小程序支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.9" data-path="redpack.html">
            
                <a href="redpack.html">
            
                    
                    微信现金红包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.10" data-path="transfers.html">
            
                <a href="transfers.html">
            
                    
                    微信企业付款
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.11" data-path="refund.html">
            
                <a href="refund.html">
            
                    
                    微信退款
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.12" data-path="wxpay-notify.html">
            
                <a href="wxpay-notify.html">
            
                    
                    服务端异步通知
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >微信H5支付</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x6587;&#x6863;&#x535A;&#x5BA2;">&#x6587;&#x6863;&amp;&#x535A;&#x5BA2;</h3>
<p><a href="https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_1" target="_blank">H5&#x652F;&#x4ED8;&#x5B98;&#x65B9;&#x6587;&#x6863;</a></p>
<h3 id="&#x63A5;&#x5165;&#x6B65;&#x9AA4;">&#x63A5;&#x5165;&#x6B65;&#x9AA4;</h3>
<ol>
<li>&#x7533;&#x8BF7;H5&#x652F;&#x4ED8;</li>
<li>&#x8C03;&#x7528;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</li>
<li>&#x901A;&#x8FC7;<code>mweb_url</code>&#x5524;&#x8D77;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x652F;&#x4ED8;</li>
<li>&#x670D;&#x52A1;&#x7AEF;&#x5F02;&#x6B65;&#x901A;&#x77E5;&#x5904;&#x7406;</li>
</ol>
<h3 id="&#x5E38;&#x89C1;&#x5F02;&#x5E38;">&#x5E38;&#x89C1;&#x5F02;&#x5E38;</h3>
<p>&#x5E38;&#x89C1;&#x5F02;&#x5E38;&#x4EE5;&#x53CA;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x8BF7;&#x53C2;&#x8003;&#x535A;&#x5BA2;-<a href="http://blog.csdn.net/zyw_java/article/details/77507835" target="_blank">&#x5FAE;&#x4FE1;H5&#x652F;&#x4ED8;</a></p>
<h3 id="&#x4EE3;&#x7801;&#x793A;&#x4F8B;">&#x4EE3;&#x7801;&#x793A;&#x4F8B;</h3>
<p><a href="https://gitee.com/javen205/IJPay-Demo" target="_blank">https://gitee.com/javen205/IJPay-Demo</a>
<a href="https://github.com/javen205/IJPay-Demo" target="_blank">https://github.com/javen205/IJPay-Demo</a></p>
<p><a href="https://gitee.com/javen205/IJPay-Demo/blob/SpringBoot/src/main/java/com/ijpay/controller/wxpay/WxPayController.java" target="_blank">Spring Boot&#x7248;&#x672C;Demo</a></p>
<pre><code>    /**
     * &#x5FAE;&#x4FE1;H5 &#x652F;&#x4ED8;
     * &#x6CE8;&#x610F;&#xFF1A;&#x5FC5;&#x987B;&#x518D;web&#x9875;&#x9762;&#x4E2D;&#x53D1;&#x8D77;&#x652F;&#x4ED8;&#x4E14;&#x57DF;&#x540D;&#x5DF2;&#x6DFB;&#x52A0;&#x5230;&#x5F00;&#x53D1;&#x914D;&#x7F6E;&#x4E2D;
     */
    @RequestMapping(value =&quot;/wapPay&quot;,method = {RequestMethod.POST,RequestMethod.GET})
    public void wapPay(HttpServletRequest request,HttpServletResponse response){
        String ip = IpKit.getRealIp(request);
        if (StrKit.isBlank(ip)) {
            ip = &quot;127.0.0.1&quot;;
        }

        H5ScencInfo sceneInfo = new H5ScencInfo();

        H5 h5_info = new H5();
        h5_info.setType(&quot;Wap&quot;);
        //&#x6B64;&#x57DF;&#x540D;&#x5FC5;&#x987B;&#x5728;&#x5546;&#x6237;&#x5E73;&#x53F0;--&quot;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;&quot;--&quot;&#x5F00;&#x53D1;&#x914D;&#x7F6E;&quot;&#x4E2D;&#x6DFB;&#x52A0;


        h5_info.setWap_url(&quot;https://pay.qq.com&quot;);
        h5_info.setWap_name(&quot;&#x817E;&#x8BAF;&#x5145;&#x503C;&quot;);
        sceneInfo.setH5_info(h5_info);

        Map&lt;String, String&gt; params = WxPayApiConfigKit.getWxPayApiConfig()
                .setAttach(&quot;IJPay H5&#x652F;&#x4ED8;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setBody(&quot;IJPay H5&#x652F;&#x4ED8;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setSpbillCreateIp(ip)
                .setTotalFee(&quot;520&quot;)
                .setTradeType(TradeType.MWEB)
                .setNotifyUrl(notify_url)
                .setOutTradeNo(String.valueOf(System.currentTimeMillis()))
                .setSceneInfo(h5_info.toString())
                .build();

        String xmlResult = WxPayApi.pushOrder(false,params);
log.info(xmlResult);
        Map&lt;String, String&gt; result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get(&quot;return_code&quot;);
        String return_msg = result.get(&quot;return_msg&quot;);
        if (!PaymentKit.codeIsOK(return_code)) {
            log.error(&quot;return_code&gt;&quot;+return_code+&quot; return_msg&gt;&quot;+return_msg);
            throw new RuntimeException(return_msg);
        }
        String result_code = result.get(&quot;result_code&quot;);
        if (!PaymentKit.codeIsOK(result_code)) {
            log.error(&quot;result_code&gt;&quot;+result_code+&quot; return_msg&gt;&quot;+return_msg);
            throw new RuntimeException(return_msg);
        }
        // &#x4EE5;&#x4E0B;&#x5B57;&#x6BB5;&#x5728;return_code &#x548C;result_code&#x90FD;&#x4E3A;SUCCESS&#x7684;&#x65F6;&#x5019;&#x6709;&#x8FD4;&#x56DE;


        String prepay_id = result.get(&quot;prepay_id&quot;);
        String mweb_url = result.get(&quot;mweb_url&quot;);

        log.info(&quot;prepay_id:&quot;+prepay_id+&quot; mweb_url:&quot;+mweb_url);
        try {
            response.sendRedirect(mweb_url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
</code></pre><p><a href="https://gitee.com/javen205/IJPay-Demo/blob/master/src/main/java/com/ijpay/controller/weixin/WxPayController.java" target="_blank">Jfinal&#x7248;&#x672C;Demo</a></p>
<pre><code>    /**
     * &#x5FAE;&#x4FE1;H5 &#x652F;&#x4ED8;
     * &#x6CE8;&#x610F;&#xFF1A;&#x5FC5;&#x987B;&#x518D;web&#x9875;&#x9762;&#x4E2D;&#x53D1;&#x8D77;&#x652F;&#x4ED8;&#x4E14;&#x57DF;&#x540D;&#x5DF2;&#x6DFB;&#x52A0;&#x5230;&#x5F00;&#x53D1;&#x914D;&#x7F6E;&#x4E2D;
     */
    public void wapPay(){
        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = &quot;127.0.0.1&quot;;
        }

        H5ScencInfo sceneInfo = new H5ScencInfo();

        H5 h5_info = new H5();
        h5_info.setType(&quot;Wap&quot;);
        //&#x6B64;&#x57DF;&#x540D;&#x5FC5;&#x987B;&#x5728;&#x5546;&#x6237;&#x5E73;&#x53F0;--&quot;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;&quot;--&quot;&#x5F00;&#x53D1;&#x914D;&#x7F6E;&quot;&#x4E2D;&#x6DFB;&#x52A0;
        h5_info.setWap_url(&quot;https://pay.qq.com&quot;);
        h5_info.setWap_name(&quot;&#x817E;&#x8BAF;&#x5145;&#x503C;&quot;);
        sceneInfo.setH5_info(h5_info);

        Map&lt;String, String&gt; params = WxPayApiConfigKit.getWxPayApiConfig()
                .setAttach(&quot;IJPay H5&#x652F;&#x4ED8;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setBody(&quot;IJPay H5&#x652F;&#x4ED8;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setSpbillCreateIp(ip)
                .setTotalFee(&quot;520&quot;)
                .setTradeType(TradeType.MWEB)
                .setNotifyUrl(notify_url)
                .setOutTradeNo(String.valueOf(System.currentTimeMillis()))
                .setSceneInfo(h5_info.toString())
                .build();

        String xmlResult = WxPayApi.pushOrder(false,params);
log.info(xmlResult);
        Map&lt;String, String&gt; result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get(&quot;return_code&quot;);
        String return_msg = result.get(&quot;return_msg&quot;);
        if (!PaymentKit.codeIsOK(return_code)) {
            ajax.addError(return_msg);
            renderJson(ajax);
            return;
        }
        String result_code = result.get(&quot;result_code&quot;);
        if (!PaymentKit.codeIsOK(result_code)) {
            ajax.addError(return_msg);
            renderJson(ajax);
            return;
        }
        // &#x4EE5;&#x4E0B;&#x5B57;&#x6BB5;&#x5728;return_code &#x548C;result_code&#x90FD;&#x4E3A;SUCCESS&#x7684;&#x65F6;&#x5019;&#x6709;&#x8FD4;&#x56DE;

        String prepay_id = result.get(&quot;prepay_id&quot;);
        String mweb_url = result.get(&quot;mweb_url&quot;);

        System.out.println(&quot;prepay_id:&quot;+prepay_id+&quot; mweb_url:&quot;+mweb_url);
        redirect(mweb_url);
    }
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="appPay.html" class="navigation navigation-prev " aria-label="Previous page: 微信APP支付">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="wxapp.html" class="navigation navigation-next " aria-label="Next page: 微信小程序支付">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"微信H5支付","level":"1.7.3.7","depth":3,"next":{"title":"微信小程序支付","level":"1.7.3.8","depth":3,"path":"doc/ijpay/wxpay/wxapp.md","ref":"doc/ijpay/wxpay/wxapp.md","articles":[]},"previous":{"title":"微信APP支付","level":"1.7.3.6","depth":3,"path":"doc/ijpay/wxpay/appPay.md","ref":"doc/ijpay/wxpay/appPay.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"doc/ijpay/wxpay/H5.md","mtime":"2018-09-07T06:36:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-27T03:48:47.613Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

